<template>
    <div>
        <div ref="query">
            <kv label="源码语言">
                <selector
                          :data="['Kotlin','Java']"
                          v-model="query.style"
                ></selector>
            </kv>
            <kv label="源码">
                <el-input type="textarea" v-model="query.code"></el-input>
            </kv>
            <div>
                <el-button @click="conn_click()">生成</el-button>
            </div>
            <textarea v-html="result"></textarea>
        </div>
    </div>
</template>

<script setup>




//定义 vue2的this,当前组件
const $self = getCurrentInstance();

//定义 $attrs
const $attrs = useAttrs();



//定义data
const $data = reactive({"query":{"code":"","style":"Kotlin"},"result":""});


const $props = defineProps({

});





const list = ref();

//定义事件
const $emit = defineEmits(["update:modelValue","loaded"]);



const conn_click = function() {
    var className = $data.query.code.match(/enum\s+class\s+(\w+)/)[1];
    if (!className) {
        jv.error("找不到枚举类名")
    }
    var c1 = $data.query.code.replaceAll("\n", " ").match(/\{(.+)\;/m)[1];
    var res = (c1 || "")
        .split(",")
        .map(it => it.trim())
        .filter(it => it)
        .map(it => it.replace("(\"", ":\"").replace("\")","\""))
        .join(",");
    $data.result = `jv.defEnum("${className}", {${res}});`;
    jv.$saveData("query",$data.query)
};

onMounted( function() {
    jv.$loadData("query", v=> $data.query = v )
} )



</script>

<style scoped lang="scss">
textarea {
    width: 100%;
    height: 80vh;
    font-family: Microsoft Yahei, Arail, Tabhoma;
    line-height: 1.8;
}
</style>
